package com.trhui.mallbook.common.utils;

import com.trhui.mallbook.common.rsa.Base64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;


/**
 * @author huangh
 * @version 1.0
 * @description 文件处理工具类
 * @date 2023/08/25 0025 14:18
 */

public class FileUtil {
    private static Logger logger = LoggerFactory.getLogger(FileUtil.class);


    /**
     * 文件转Base64
     * @param file
     * @return
     */
    public static String fileToBase64(File file) {
        String base64String = null;
        if (null == file || !file.exists()){
            return null;
        }

        try {
            base64String = Base64.encode(Files.readAllBytes(Paths.get(file.toURI())));
        } catch (IOException e) {
            logger.error("{}",e);
        }
        return base64String;
    }
}
